package com.lovo.common.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.amqp.rabbit.annotation.EnableRabbit;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@EnableRabbit
public class TopicMQConfig {
    @Bean
    public TopicExchange topicExchange(){
        return new TopicExchange("shop.topic.exchange",true,false);
    }
    @Bean
    public Queue topicQueueA(){
        return new Queue("shop.topic.queue.a",true);
    }
    @Bean
    public Queue topicQueueB(){
        return new Queue("shop.topic.queue.b",true);
    }
    @Bean
    public Queue topicQueueC(){
        return new Queue("shop.topic.queue.c",true);
    }

    @Bean
    public Binding topicExchangeQueueABinding(){
        //队列A绑定到TopicExchange交换机
         return BindingBuilder.bind(topicQueueA()).to(topicExchange()).with("topic.msg");
    }
    @Bean
    public Binding topicExchangeQueueBBinding(){
        //队列B绑定到TopicExchange交换机
        return BindingBuilder.bind(topicQueueB()).to(topicExchange()).with("topic.#");
    }
    @Bean
    public Binding topicExchangeQueueCBinding(){
        //队列C绑定到TopicExchange交换机
        return BindingBuilder.bind(topicQueueC()).to(topicExchange()).with("topic.*");
    }

}
